package com.htht.smartschool.common.servlet;

import com.google.gson.Gson;
/**
 * 存储处理结果
 * 自动转化为JSON对象
 * @author David
 *
 */
public class Result {

	private int  result=1; 
	String error="";
	Object data=null;
	String sessionid;
	Object remark;
	public Object getRemark() {
		return remark;
	}
	public void setRemark(Object remark) {
		this.remark = remark;
	}
	public String getSessionid() {
		return sessionid;
	}
	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}


	/**
	 * type:推送消息时区分消息类型
	 *  0: 一般结果
	 *  1:
	 *  2:
	 */
	int  type = 0; 
	
	/**
	 * 1 表示成功 ，默认值
	 * 0 表示出现错误
	 * @return
	 */
	public int getResult() {
		return result;
	}
	public void setResult(int result) {
		this.result = result;
	}
	public String getError() {
		return error;
	}
	
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	
	public int  getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	
	public void setOK(Object data){
		result=1;
		this.data=data;
		this.error="";
	}
	public void setError(String msg){
		result=0;
		this.error=msg;
		this.data="";
	}
	public void setOKError(String msg){
		result=1;
		this.error=msg;
		this.data="";
	}
	
	public String toJSON(){
		try {
			Gson gson = new Gson();
			return gson.toJson(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return error;
	}
}
